home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrecord-1.8.1 / lib / swabbytes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-04  |  1.2 KB  |  42 lines

  1. /* @(#)swabbytes.c    1.4 96/02/04 Copyright 1988 J. Schilling */
  2. /*
  3.  *    swab bytes in memory
  4.  *
  5.  *    Copyright (c) 1988 J. Schilling
  6.  */
  7. /* This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2, or (at your option)
  10.  * any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; see the file COPYING.  If not, write to
  19.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  20.  */
  21.  
  22. #include <standard.h>
  23.  
  24. #define    DO8(a)    a;a;a;a;a;a;a;a;
  25.  
  26. void swabbytes(vp, cnt)
  27.          void    *vp;
  28.     register int    cnt;
  29. {
  30.     register char    *bp = (char *)vp;
  31.     register char    c;
  32.  
  33.     cnt /= 2;    /* even count only */
  34.     while ((cnt -= 8) >= 0) {
  35.         DO8(c = *bp++; bp[-1] = *bp; *bp++ = c;);
  36.     }
  37.     cnt += 8;
  38.     while (--cnt >= 0) {
  39.         c = *bp++; bp[-1] = *bp; *bp++ = c;
  40.     }
  41. }
  42.